﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers.waitingQueue {
    import net.wooga.pets.loading.vos.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.models.world.vos.actors.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.world.*;

    public class PickNewPatientCommand extends Command {

        public var event:InfoEvent;
        public var worldModel:WorldModel;

        override public function execute():void{
            var _local1:Object = {index:this.event.id};
            var _local2:RequestEvent = new RequestEvent(EventConstants.SEND_REQUEST, this.onResult);
            _local2.addRequest("pick_patient", _local1);
            dispatch(_local2);
        }
        private function onResult(_arg1:ResultVO):void{
            var _local2:Object;
            var _local3:Array;
            if (_arg1.success){
                _local2 = _arg1.data.pick_patient;
                _local3 = _local2.queue_added;
                this.moveExisitingUpInQueue((this.event.info as WaitingPetVO));
                dispatch(new InfoEvent(EventConstants.REMOVE_FROM_QUEUE, this.event.id, this.event.info));
                dispatch(new InfoEvent(EventConstants.CREATE_PATIENT, null, _local2.pet));
                dispatch(new InfoEvent(EventConstants.ADD_NEW_PET_TO_QUEUE, null, _local3));
            };
        }
        private function moveExisitingUpInQueue(_arg1:WaitingPetVO):void{
            var _local4:WaitingPetVO;
            var _local2:IWaitingQueue = (this.worldModel.getRoomById(_arg1.roomId) as IWaitingQueue);
            _local2.removeActor(_arg1.id);
            var _local3:Array = _local2.waitingQueue;
            for each (_local4 in _local3) {
                dispatch(new InfoEvent(EventConstants.MOVE_UP_IN_QUEUE, _local4.id));
            };
        }

    }
}//package net.wooga.pets.controllers.waitingQueue 
